package com.sharemedia.managers.db
{
	import com.sharemedia.interfaces.IDBCommand;
	import com.sharemedia.vos.Track;
	
	import flash.data.SQLConnection;
	import flash.data.SQLStatement;
	import flash.events.Event;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	
	public class UpdateTrackInfoCommand implements IDBCommand
	{
		private const INFO_TRACK:String = "UPDATE tracks SET songName = @songName, artist = @artist, length = @length WHERE uid=@uid";
		
		private var track:Track;
		
		public function UpdateTrackInfoCommand( track:Track)
		{
			this.track = track;
		}
		
		public function execute(connection:SQLConnection):void
		{
			var addTracksStat:SQLStatement = new SQLStatement();
			addTracksStat.sqlConnection = connection;
			addTracksStat.text = INFO_TRACK;
			
			addTracksStat.addEventListener(SQLErrorEvent.ERROR, errorHandler);
			addTracksStat.addEventListener(SQLEvent.RESULT, insertResultHandler);
			
			addTracksStat.parameters["@uid"] = track.uid;	
			if(track.info)
			{
				addTracksStat.parameters["@songName"] = track.info.name;	
				addTracksStat.parameters["@artist"] = track.info.artist
			}
			addTracksStat.parameters["@length"] = track.length;	
			
			addTracksStat.execute();
		}
		
		/**
		 */
		private function errorHandler(e:SQLErrorEvent):void
		{
		}
		
		protected function insertResultHandler(event:Event):void
		{
		}
	}
}